﻿namespace Nuclear.Models.DtoModels;

public class ErrorDto
{
    public ErrorCode Code { get; set; } = ErrorCode.Success;
    public string? Message { get; set; }
    public string? UserMessage { get; set; }
}

public enum ErrorCode
{
    Success = 200,
    InvalidRequest = 400,
    Unauthorized = 401,
    InvalidSystemId = 411,
    InvalidConsumeCode = 412,
    InvalidDateRange = 413,
    ConsumeCodeNotFound = 420,
    InternalError = 500,
    ConsumeCodeAlreadyUsed = 601,
    DuplicateConsumeCodeFound = 602,
    ConsumeCodeExpired = 603,
    ConsumeCodeNotActiveYet = 604,
    UserNameOrPasswordIncorrect = 611,
    SystemLoginNotSupported = 700
}

public static class ErrorResponse
{
    public static T Create<T>(ErrorCode code, string message, string userMessage)
        where T: BaseResponseDto, new() =>
        Create<T>(new ErrorDto
        {
            Code = code,
            Message = message,
            UserMessage = userMessage
        });

    public static T Create<T>(ErrorDto error)
        where T : BaseResponseDto, new() =>
        new()
        {
            Error = error
        };
}